<?php

namespace app\index\controller;

class Data
{
    public function __construct()
    {
        //表模型
        $this->news = db('news');
        $this->join = db('join');
        $this->place = db('place');
        $this->price = db('price');
        $this->line = db('line');
    }

    public function news($page = 1, $limit = 15, $map = array())
    {
        $data['data'] = $this->news->where($map)->order("id desc")->page($page, $limit)->field("id,title,thumb,inputtime,viewcount,updatetime")->select();
        $data['count'] = $this->news->where($map)->count();
        return $data;
    }

    public function join($arr)
    {
        $res = $this->join->insert($arr);
        if ($res) {
            return 1;
        } else {
            return 0;
        }
    }


    public function place($page = 1, $limit = 15, $map = array())
    {
        $data['data'] = $this->place->where($map)->order("id desc")->page($page, $limit)->select();
        $data['count'] = $this->place->where($map)->count();
        return $data;
    }

    public function price($page = 1, $limit = 15, $map = array())
    {
        $data['data'] = $this->price->where($map)->order("id desc")->page($page, $limit)->select();
        $data['count'] = $this->price->where($map)->count();
        return $data;
    }

    public function line($page = 1, $limit = 15, $map = array())
    {
        $data['data'] = $this->line->where($map)->order("id desc")->page($page, $limit)->select();
        foreach ($data['data'] as $k => $v) {
            $data['data'][$k]['starttime']=get_data()[$v['starttime']];
            $data['data'][$k]['stoptime']=get_data()[$v['stoptime']];
        }
        $data['count'] = $this->line->where($map)->count();
        return $data;
    }


    public function detail($id)
    {
        $data=$this->news->find($id);
        if($data){
            $data['content']=html_entity_decode($data['content']);
        }
        return $data;
    }
}
